

jQuery(function ($) {

    var pageOnoff = true;
    getList(0);
    //分页按钮
    function twbsPagination(data) {
        Page({
			num: Math.ceil(data / 20),					//页码数
			startnum:1,				//指定页码
			elem:$('#pagination_b'),		//指定的元素
			callback:function(page){	//回调函数
                if (page == 1) {
                    return;
                }
                $('.works_show').empty();
                getList(page - 1);
			}
		});
    }
    //通知公告列表
    function getList(page) {
        var params = {
            '[]': {
                'page': page,
                'count': 20,
                'Notice': {
                    '@order': 'rank-',
                    'level_id': '1'
                }
            }

        };
        send_ajax('post', '/get', params, function callback(res) {
            if (res.code == 200&&res["[]"]) {
                var data = res["[]"];
                for (var i = 0; i < data.length; i++) {
                    $('.content_list').append('<li>\n                <p class="li_title">\n                    <span class="title_left">\n                        ' + data[i].Notice.title + "\n                    </span>\n                    <span class=\"time\">\n                        \u3010\u6613\u4ECE\u8D44\u8BAF\u3011 " + data[i].Notice.create_time + " \u66F4\u65B0\n                    </span>\n                </p>\n                <p class=\"li_content\">\n                    <span>" + data[i].Notice.content + '</span>\n               <a href="/notice/notice_detail?notice-' + data[i].Notice.id + ".html\" target=\"_blank\"><span class=\"red\">[\u5168\u6587]</span>\n </a>                    </p>\n            </li>");
                }
            }
            if (pageOnoff) {
                //分页按钮
                twbsPagination();
                pageOnoff=false;
            }
        });
    }

    requestMainNav();
    //获取主导航
    function requestMainNav() {
        var params = {
            "Nav[]": {
                "Nav": {
                    "type": 1,
                    "@order": "rank-",
                    "use_flag": 1
                }
            },
            "Tdk": {
                "type": 1
            }
        };

        send_ajax('post', '/get', params, function callback(res) {
            if (res.code = 200&& res["Nav[]"]) {
                var data = res["Nav[]"];
                var html = '';
                for (var i = 0; i < data.length; i++) {

                    var a_nav = data[i];

                    var temp = '<a href="' + a_nav.url + '" target="_blank">' + a_nav.name + '</a>';

                    html += temp;
                }
                $('.main_head nav').html(html);

                //tdk
                var placeholder = res.Tdk.placeholder;
                var search_keywords = res.Tdk.tdk_search_keywords;

                $('.search input').placeholder = placeholder;

                var keywords_html = '';
                var keywords_arr = search_keywords.split(',');
                for (var _i = 0; _i < keywords_arr.length; _i++) {
                    var words = keywords_arr[_i];
                    var _temp = '<li><a href="/goods/goods_search.html?keywords=' + words + '" target="_blank">' + words + '</a></li>';
                    keywords_html += _temp;
                }

                $('.list_nav').html(keywords_html);
            } else {
                alert('网络加载失败，请稍后再试！');
            }
        });
    }
});